package jwdt.xadmin.added.action;

import jwdt.common.action.BaseAction;
import jwdt.xadmin.added.bean.TVote;
import jwdt.xadmin.added.service.VoteManageService;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/added")
public class VoteManageAction extends BaseAction {

	private VoteManageService voteManageService = (VoteManageService)app.getBean("voteManageService");
	
	@RequestMapping("/listVote")
	public Page doListVote(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		return m.getWritePage(f, voteManageService.doList(pu).toJson());
	}
	
	@RequestMapping("/addVote")
	public Page doAddact(Form f, Module m) throws Exception {
		TVote obj = (TVote)f.copy2Class(TVote.class);
		return m.getWritePage(f, voteManageService.doAddact(obj));
	}
	
	@RequestMapping("/editVote")
	public Page doEditact(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		TVote obj = (TVote)f.copy2Class(TVote.class);
		return m.getWritePage(f, voteManageService.doEditact(obj, id));
	}
	
	@RequestMapping("/delVote")
	public Page doDel(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		return m.getWritePage(f, voteManageService.doDelact(id));
	}
	
	@RequestMapping("/checkVote")
	public Page doCheck(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		int result = f.getInt("result");
		return m.getWritePage(f, voteManageService.doUpdateState(id,"ischecked="+result));
	}
	
	@RequestMapping("/voteWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		f.add("obj", voteManageService.doLoad(id));
		return m.findPage("/xadmin/added/voteWindow");
	}
}
